<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="所属用户" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入所属用户"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="姓名" prop="realName">
        <el-input
          v-model="queryParams.realName"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="证件号码" prop="certificateCode">
        <el-input
          v-model="queryParams.certificateCode"
          placeholder="请输入证件号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:appUserApply:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:appUserApply:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:appUserApply:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:appUserApply:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="appUserApplyList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="所属用户" align="center" prop="userId" />
      <el-table-column label="姓名" align="center" prop="realName" />
      <el-table-column label="手机号" align="center" prop="phone" />
      <el-table-column label="证件类型" align="center" prop="certificateType" />
      <el-table-column width="120"  show-overflow-tooltip  label="证件号码" align="center" prop="certificateCode" />
      <el-table-column  label="证件有效期" align="center" prop="validityTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.validityTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="性别" align="center" prop="sex">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sex"/>
        </template>
      </el-table-column>
      <el-table-column label="出生日期" align="center" prop="birthday" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.birthday, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="出险日期" align="center" prop="occurTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.occurTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column   width="120" show-overflow-tooltip  label="出险描述" align="center" prop="occurDes" />
      <el-table-column label="领款姓名" align="center" prop="lingkuanRealName" />
      <el-table-column width="100" show-overflow-tooltip label="领款银行名称" align="center" prop="lingkuanBlankName" />
      <el-table-column width="100" show-overflow-tooltip  label="领款银行卡号" align="center" prop="lingkuanBlanCode" />
      <el-table-column label="关系证明图" align="center" prop="relationshipImages" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.relationshipImages" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="银行卡图" align="center" prop="blankImages" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.blankImages" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="医疗费用图" align="center" prop="yiliaoImages" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.yiliaoImages" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="病历图" align="center" prop="bingImages" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.bingImages" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column fixed="right" width="150" label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:appUserApply:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:appUserApply:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改理赔申请对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="所属用户" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入所属用户" />
        </el-form-item>
        <el-form-item label="姓名" prop="realName">
          <el-input v-model="form.realName" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="手机号" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入手机号" />
        </el-form-item>
        <el-form-item label="证件号码" prop="certificateCode">
          <el-input v-model="form.certificateCode" placeholder="请输入证件号码" />
        </el-form-item>
        <el-form-item label="证件有效期" prop="validityTime">
          <el-date-picker clearable
            v-model="form.validityTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择证件有效期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-select v-model="form.sex" placeholder="请选择性别">
            <el-option
              v-for="dict in dict.type.sys_user_sex"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="出生日期" prop="birthday">
          <el-date-picker clearable
            v-model="form.birthday"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择出生日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="出险日期" prop="occurTime">
          <el-date-picker clearable
            v-model="form.occurTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择出险日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="出险描述" prop="occurDes">
          <el-input v-model="form.occurDes" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="领款姓名" prop="lingkuanRealName">
          <el-input v-model="form.lingkuanRealName" placeholder="请输入领款姓名" />
        </el-form-item>
        <el-form-item label="领款银行名称" prop="lingkuanBlankName">
          <el-input v-model="form.lingkuanBlankName" placeholder="请输入领款银行名称" />
        </el-form-item>
        <el-form-item label="领款银行卡号" prop="lingkuanBlanCode">
          <el-input v-model="form.lingkuanBlanCode" placeholder="请输入领款银行卡号" />
        </el-form-item>
        <el-form-item label="关系证明图" prop="relationshipImages">
          <image-upload v-model="form.relationshipImages"/>
        </el-form-item>
        <el-form-item label="银行卡图" prop="blankImages">
          <image-upload v-model="form.blankImages"/>
        </el-form-item>
        <el-form-item label="医疗费用图" prop="yiliaoImages">
          <image-upload v-model="form.yiliaoImages"/>
        </el-form-item>
        <el-form-item label="病历图" prop="bingImages">
          <image-upload v-model="form.bingImages"/>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAppUserApply, getAppUserApply, delAppUserApply, addAppUserApply, updateAppUserApply } from "@/api/system/appUserApply"

export default {
  name: "AppUserApply",
  dicts: ['sys_user_sex'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 理赔申请表格数据
      appUserApplyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        realName: null,
        phone: null,
        certificateType: null,
        certificateCode: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        realName: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
        phone: [
          { required: true, message: "手机号不能为空", trigger: "blur" }
        ],
        certificateType: [
          { required: true, message: "证件类型不能为空", trigger: "change" }
        ],
        certificateCode: [
          { required: true, message: "证件号码不能为空", trigger: "blur" }
        ],
        validityTime: [
          { required: true, message: "证件有效期不能为空", trigger: "blur" }
        ],

      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询理赔申请列表 */
    getList() {
      this.loading = true
      listAppUserApply(this.queryParams).then(response => {
        this.appUserApplyList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        realName: null,
        phone: null,
        certificateType: null,
        certificateCode: null,
        validityTime: null,
        sex: null,
        birthday: null,
        occurTime: null,
        occurDes: null,
        lingkuanRealName: null,
        lingkuanBlankName: null,
        lingkuanBlanCode: null,
        relationshipImages: null,
        blankImages: null,
        yiliaoImages: null,
        bingImages: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null,

      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加理赔申请"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getAppUserApply(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改理赔申请"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAppUserApply(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addAppUserApply(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除理赔申请编号为"' + ids + '"的数据项？').then(function() {
        return delAppUserApply(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/appUserApply/export', {
        ...this.queryParams
      }, `appUserApply_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
